# from home.models import Article
# import json
#
# def commom_data(request):
#     hot_tags = Article.objects.values('tags').order_by('-total_views').distinct()[:9]
#     if request.COOKIES.get("login.html") is not None:
#         username = json.loads(request.COOKIES.get("login.html"))
#     else:
#         username = ""
#     # 2-3、最新文章
#     new_arts = Article.objects.order_by('-create_time')[:5]
#     return {"hot_tags": hot_tags,"new_arts": new_arts,'username':username,}

from home.models import *
import json

def comm_hottages_news(request):
    categories = ArticleCategory.objects.all()

    # 重新查询文章信息，按照浏览量降序排序（热门标签）
    hot_tags = Article.objects.values('id','tags').order_by('-total_views').distinct()[:9]
    # 最新文章
    new_arts = Article.objects.order_by('-create_time')[:5]
    if 'login_name' in request.COOKIES:
        username = request.COOKIES.get('login_name')
        username = json.loads(username)
    else:
        username = ''
    return {
        'hot_tags': hot_tags,
        'new_arts': new_arts,
        "categories":categories,
        "username":username
    }